<template>
    <div>
        <el-table :data="store.state.role.roleList" border style="width: 100%">
            <el-table-column prop="id" label="角色编号" width="180" />
            <el-table-column prop="rolename" label="角色名称" width="180" />
            <el-table-column label="状态">
                <template v-slot="a">
                    <el-tag type="success" v-if="a.row.status == 1">启用</el-tag>
                    <el-tag type="danger" v-if="a.row.status == 2">禁用</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template v-slot="a">
                    <el-button plain type="primary" @click="edit(a.row.id)">编辑</el-button>
                    <el-button plain type="danger" @click="del(a.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
  
<script lang="ts" setup>
import mit from '../../common/myMitt';
import { useStore } from "vuex";
import { roledelete } from '../../request/api';
import { ElMessage } from "element-plus";
import { getCurrentInstance } from "vue";

let getapp: any = getCurrentInstance();
let store = useStore();

store.dispatch('role/getRoleList');

function edit(id: number) {
    mit.emit('getInfo', id);
}

function del(id: number) {
    getapp.appContext.config.globalProperties.$del(() => {
        roledelete({ id }).then((res: any) => {
            if (res.code == 200) {
                ElMessage.success(res.msg);
                store.dispatch('role/getRoleList');
                return;
            }
            ElMessage.warning(res.msg);
        })
    })
}
</script>
  
<style lang="scss" scoped></style>